#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "src/list.h"


static float start_time;
static float nnodes = 10000000;


static float cpu()
{
    return 0;
}


static void bm(const char *label, void(*fn)())
{
    printf(" %18s", label);
    fflush(stdout);
    fn();
}


static void start()
{
    start_time = cpu();
}

static void stop()
{
    float druation = cpu() - start_time;
    printf(": \x1b[32m%.4f\x1b[0ms\n", druation);
}

int elem_cmp(const void *a, const void *b)
{
    return strncmp(a, b, strlen(a));
}


void bm_add()
{
    start();
    int n = nnodes;
    list_t *l = list_new(n, NULL);
    while (n--) {
        list_add(l, "foo");
    }
    stop();
}

void bm_add_noduplicate()
{
    start();
    stop();
}

void bm_find()
{
    start();
    int n = nnodes;
    list_t *l = list_new(n, NULL);
    while (--n) {
        list_add(l, "foo");
    }
    list_add(l, "bar");
    assert(0 == strncmp(list_find(l, "bar", elem_cmp), "bar", 3));
    stop();
}

void bm_remove()
{
    start();
    stop();
}

void bm_remove_cmp()
{
    start();
    stop();
}


void bm_copy()
{
    start();
    stop();
}

int main(int argc, char *argv[])
{
    bm("add", bm_add);
    bm("add_noduplicate", bm_add_noduplicate);
    bm("find", bm_find);
    bm("remove", bm_remove);
    return 0;
}


